function AnimateOrbit_MultiMoon(t_all,S_all,DU,thetao,theta_dot,central_radius,eventTime)

%% Interp data
dt = 20000;
tnew = t_all(1):dt:t_all(end);
% interp time vector

R = S_all(1:3,:);
%[] Position

Rnew = [interp1(t_all,R(1,:),tnew); ...
    interp1(t_all,R(2,:),tnew); ...
    interp1(t_all,R(3,:),tnew)];
%[] New position vector

n = numel(tnew);
%[] Number of elements

for ii = 1:length(eventTime)
    temp_find_index = tnew-eventTime(ii);
    plotBurnIndex(ii) = find(temp_find_index>0,1);
end
%[] Determine index where the burn plot should appear
%% Determine Moon positions
n_moon = size(DU,1);
%[] Number of Moons

moonPosition = cell(1,n_moon);
%[] Moon's position vector storage

for ii = 1:n_moon
    moonPosition{ii} = zeros(3,n);
    for jj = 1:n
        thetaf = thetao(ii)+theta_dot(ii)*tnew(jj);
        moonPosition{ii}(:,jj) = DU(ii)*[cos(thetaf);sin(thetaf);0];
    end
end
%[] Determine moon's position

range = zeros(1,n);
%[] Preallocate memory for range to find max extent for figure;

for ii = 1:n
    range(ii) = norm(moonPosition{end}(1:3,ii));
end
%[] Loop through last moon

Extent = max(range);
%[] Determine maximum range for plotting.

%%
% ScreenSize = get(0,'ScreenSize');

ScreenSize = [1,1,1000,1000];
%[]Determines the location and dimensions of the current monitor.

Window = figure( ...
    'Color','k', ...
    'MenuBar','None', ...
    'Name','ORBIT ANIMATION', ...
    'NumberTitle','Off', ...
    'OuterPosition',ScreenSize, ...
    'Resize','Off', ...
    'ToolBar','None');
%[]Opens a new window and adjusts its properties.

Axes = axes( ...
    'CameraPosition',Extent*[0,0,1], ...
    'CameraTarget',[0,0,0], ...
    'Color','k', ...
    'Parent',Window, ...
    'PlotBoxAspectRatio',[1,1,1], ...
    'NextPlot','Add', ...
    'XColor','k', ...
    'YColor','k', ...
    'ZColor','k', ...
    'XLim',Extent * [-1,1], ...
    'YLim',Extent * [-1,1], ...
    'ZLim',Extent * [-1,1]);
%[]Adds an axes to the specified window and adjusts its properties.

colors = {'r','b','c','y','w','m','g','r'};
%[] list the colors

[xe,ye,ze] = ellipsoid(0,0,0,central_radius,central_radius,central_radius,50);
%[Earth radii]Determines the coordinates of the Earth.

for k = 1:n
    
    cla(Axes);
    %[] Clear axis to draw new ones
    
    Surface = surface(xe,ye,-ze, ...
        'EdgeColor','None', ...
        'Parent',Axes);
    %[]Adds a plot to the specified axes and adjusts its properties.
    
    plot3(Rnew(1,1:k),Rnew(2,1:k),Rnew(3,1:k), ...
        'Color','w', ...
        'LineStyle','--', ...
        'Marker','.', ...
        'MarkerSize',20,...
        'Parent',Axes);
    %[]Adds a plot to the specified axes and adjusts its properties.
    
    plot3(Rnew(1,k),Rnew(2,k),Rnew(3,k), ...
        'Color','w', ...
        'LineStyle','None', ...
        'Marker','.', ...
        'MarkerSize',35, ...
        'Parent',Axes);
    %[]Adds a plot to the specified axes and adjusts its properties.
    
    for ii = 1:n_moon
        plot3(moonPosition{ii}(1,1:k),moonPosition{ii}(2,1:k),moonPosition{ii}(3,1:k), ...
            'Color',colors{ii}, ...
            'LineStyle','None', ...
            'Marker','.', ...
            'Parent',Axes);
        %[]Adds a plot to the specified axes and adjusts its properties.
        
        plot3(moonPosition{ii}(1,k),moonPosition{ii}(2,k),moonPosition{ii}(3,k), ...
            'Color',colors{ii}, ...
            'LineStyle','None', ...
            'Marker','.', ...
            'MarkerSize',35, ...
            'Parent',Axes);
        %[]Adds a plot to the specified axes and adjusts its properties.
    end
    
    plot3([0,Extent],[0,0],[0,0], ...
        'Color','r', ...
        'LineStyle','-', ...
        'LineWidth',3, ...
        'Marker','None', ...
        'Parent',Axes);
    %[]Adds a plot to the specified window and adjusts its properties.
    
    text( ...
        'BackGroundColor','k', ...
        'Color','y', ...
        'FontName','Arial', ...
        'FontSize',20, ...
        'FontWeight','Bold', ...
        'HorizontalAlignment','Center', ...
        'LineStyle','None', ...
        'Parent',Axes, ...
        'Position',[Extent,0,0], ...
        'String','\Upsilon', ...
        'VerticalAlignment','Middle');
    %[] Plot first point of aries vector
    
    for ii = 1:length(eventTime)
        if k>plotBurnIndex(ii)
            plot3(Rnew(1,plotBurnIndex(ii)),Rnew(2,plotBurnIndex(ii)),Rnew(3,plotBurnIndex(ii)), ...
                'Color','r', ...
                'LineStyle','None', ...
                'Marker','p', ...
                'MarkerFaceColor','r', ...
                'MarkerSize',15, ...
                'Parent',Axes);            
        end
    end
    %[] Plot event locations 
    
    pause(0.0001)
    %[] Plot
    
end




end
